<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class Users extends Model
{
    protected $table = 'users';
    protected $primaryKey = 'id';

    public static function getUserByOpenid($openid)
    {
        return self::select("openid","head_img","nike","domain","phone","corp_type")->where("openid",$openid)->first();
    }

    public static function adminUserList($code)
    {
        $query = self::query();
        if (!empty($code)) $query->where("code",$code);
        return $query->orderBy("id","DESC")->paginate(20);
    }

    public static function getUserByPhone($phone)
    {
        return self::where("phone",$phone)->first();
    }

    public static function updateUsers($openid,$head_img)
    {
        return self::where("openid",$openid)->update(["head_img"=>$head_img,"nike"=>$nike]);
    }

    public static function updateSetting($openid,$nike,$head_img,$phone)
    {
        return self::where("openid",$openid)->update(["nike"=>$nike,"head_img"=>$head_img,"phone"=>$phone]);
    }

    public static function passwordUpdate($openid,$password)
    {
        return self::where("openid",$openid)->update(["password"=>$password]);
    }

    public static function creatUsers($phone,$password)
    {
        return self::insertGetId(["phone"=>$phone,"password"=>$password,"created_at"=>time()]);
    }

    public static function usersAdd($openid,$appid,$head_img,$nike,$code)
    {
        return self::insert(["openid"=>$openid,"appid"=>$appid,"head_img"=>$head_img,"nike"=>$nike,"code"=>$code,"created_at"=>time()]);
    }

    public static function userCorpType($openid,$corp_type)
    {
        return self::where("openid",$openid)->update(["corp_type"=>$corp_type]);
    }

    public static function updateUserDisable($openid,$disable)
    {
        return self::where("openid",$openid)->update(["disable"=>$disable]);
    }
}